#!/bin/bash
#######################
#脚本使用方法：
#本脚本和jar包在同一目录下，保证当前目录有且只有一个jar包即可。无需修改任何东西。
# Usage: $0 {start|stop|status|restart}
#######################
#可在此处添加需要加载的环境变量
#######################
CurrentPath=`pwd`

APPDIR=${CurrentPath%/*}

APP_NAME=$APPDIR/lib/zyplayer-doc-es-0.0.1-SNAPSHOT.jar


is_exist () {
    pid=`ps aux | grep $APP_NAME | grep -v grep | grep "jar$"| awk '{print $2}'`
    if [ -z "$pid" ];then
        return 1
    else
        return 0
    fi
}
start () {
    is_exist
    if [ $? -eq 0 ];then
        echo "${APP_NAME} is already running. pid=${pid} ."
    else
        nohup java -Dspring.config.location=$APPDIR/conf/ -jar ${APP_NAME} > $APPDIR/logs/nohup.log 2>&1 &
    fi
}
stop () {
    is_exist
    if [ $? -eq 0 ];then
        kill  $pid
    else
        echo "${APP_NAME} is not running"
    fi
}
status () {
    is_exist
    if [ $? -eq 0 ];then
        echo "${APP_NAME} is running. Pid is ${pid}"
    else
        echo "${APP_NAME} is not running"
    fi
}
case $1 in
    start)
        start;;
    stop)
        stop;;

    restart)
        stop
        start;;
    status)
        status;;
    *)
        echo "Usage: $0 {start|stop|status|restart} "
esac